package org.edu.modules.oa.controller;


import groovy.util.logging.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.vo.LoginUser;
import org.edu.common.util.RedisUtil;
import org.edu.modules.oa.entity.VeOaTongxunluEntity;
import org.edu.modules.oa.service.IVeOaTongxunluService;
import org.edu.modules.oa.vo.VeOaTongxunluVo;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Api(tags="共享通讯录")
@RestController
@RequestMapping("oa/VeOaSharedTongxunlu")
@Slf4j
public class VeOaSharedTongxunluController {


    @Autowired
    private RedisUtil redisUtil; // redis服务类
    @Resource
    private IVeOaTongxunluService iVeOaTongxunluService;


    //日志注解
    @AutoLog(value = "共享通讯录-显示表格")
    @ApiOperation(value = "显示表格",notes = "共享通讯录-显示表格")
    //显示表格  查询（共享通讯录）
    @PostMapping(value = "/searchTable")
    public Result<?> showTable(Integer startPage, Integer pageSize, VeOaTongxunluEntity veOaTongxunluEntity){
       //共享
        veOaTongxunluEntity.setIsShare(0);
        HashMap<String,Object> map = iVeOaTongxunluService.selectTongxunlu(veOaTongxunluEntity,startPage,pageSize);
        return Result.OK(map);

    }

    //多个导出
    @AutoLog(value = "共享通讯录-单个导出excel表格")
    @ApiOperation(value = "单个导出excel表格", notes = "共享通讯录-单个导出excel表格")
    @GetMapping(value = "/exportTongxunluTableOne")
    //ModelAndView 导出表格流
    public ModelAndView exportTongxunluTableOne(){
        VeOaTongxunluEntity veOaTongxunluEntity = new VeOaTongxunluEntity();
        //获取登录人信息
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        //查共享的全部通讯录 0是
        veOaTongxunluEntity.setIsShare(0);
        List<VeOaTongxunluVo> voList = iVeOaTongxunluService.export(veOaTongxunluEntity);
        //创建导出流
        ModelAndView modelAndView = new ModelAndView(new JeecgEntityExcelView());
        //文件的文件名
        modelAndView.addObject(NormalExcelConstants.FILE_NAME,"共享通讯录");
        //数据的类型
        modelAndView.addObject(NormalExcelConstants.CLASS,VeOaTongxunluVo.class);
        // ExportParams  Export工具类   （参数1--》title:表格标题  参数2--》secomdTitle:第二行的标题，  参数3--》secomdTitle:最下面尾部的信息）
        ExportParams exportParams = new ExportParams("共享通讯录","导出人:"+user.getRealname(),"导出共享通讯录信息");
        modelAndView.addObject(NormalExcelConstants.PARAMS,exportParams);
        modelAndView.addObject(NormalExcelConstants.DATA_LIST,voList);

        return modelAndView;
    }







}
